package cn.shop.cloud.common;


import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: work
 * @ClassName CommonControllerAdvice
 * @description:
 * @author: 李尧坤
 * @create: 2024−12-19 19:34
 * @Version 1.0
 **/
@ControllerAdvice
public class CommonControllerAdvice {
    @ExceptionHandler(BusinessException.class)
    @ResponseBody
    public Result handlerBusinessException(BusinessException ex){

        return Result.error(ex.getCodeMsg());
    }


    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result handlerDefaultException(Exception ex){

        //打印堆栈信息
        ex.printStackTrace();

        return Result.defaultError();
    }
}
